﻿using System.Collections.Generic;
using LoungeRepo.Contracts.Normalizer;
using LoungeRepo.Normalizer.DataStructures;


namespace LoungeRepo.Normalizer
{
    internal partial class ObjectGraphNormalizer
    {
        private readonly Dictionary<object, INormalizedObjectReference> normalizedObjectCache = new Dictionary<object, INormalizedObjectReference>();
        private readonly IList<INormalizedEntity> normalizedEntities = new List<INormalizedEntity>();


        public IEnumerable<INormalizedEntity> NormalizeEntityGraph(object entityObject)
        {
            NormalizeEntity(entityObject);
            return this.normalizedEntities;
        }


        internal NormalizedEntityReference NormalizeEntity(object entityObject)
        {
            NormalizedEntity normalizedEntity = CreateNormalizedEntityToBeFilled(entityObject);
            NormalizedEntityReference normalizedEntityRef = CreateReferenceToNormalizedEntity(entityObject);

            TransferObjectIntoNormalizedObject(entityObject, normalizedEntity);

            return normalizedEntityRef;
        }


        internal NormalizedObject NormalizeNonEntity(object nonEntity)
        {
            NormalizedObject normalizedObject = CreateNormalizedObjectToBeFilled(nonEntity);

            TransferObjectIntoNormalizedObject(nonEntity, normalizedObject);

            return normalizedObject;
        }
    }
}
